home *** CD-ROM | disk | FTP | other *** search
- Path: emerald.tufts.edu!rdorich
- From: rdorich@emerald.tufts.edu (Roberto Dorich)
- Newsgroups: comp.lang.c
- Subject: automatic charrs
- Date: 24 Feb 1996 01:19:05 GMT
- Organization: Tufts University
- Message-ID: <4glp29$dsh@d2.tufts.edu>
- NNTP-Posting-Host: emerald.tufts.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Hello,
-
- Could someone enlighten me, and tell me why the following program runs
- just dandy using Sun's cc (3.0.1), but crashes using gcc (?) ?
-
- #include <stdio.h>
- char *b() { return "Hello";}
-
- main() {
- char *a=b();
-
- a[0]='X';
- printf("--> %s\n",a);
- }
-
- Esentially, gcc puts out the following assembly code:
-
- call b,0
- nop
- mov 88,%o1 // %o1 = 'X'
- stb %o1, [%o0] // a[0] = %o1
-
- And cc spits out the following:
-
- call b
- nop
- mov 88,%l1
- stb %l1,[%l0+0]
-
- (this assembly code has been optimized by me :-/ )
-
- Anyway, there isn't really that much difference... but I get a seg fault
- with gcc. Why?
-
- Thanks!
-
- Roberto
-
- --
-
- Roberto Dorich o SKI rdorich@ee.cornell.edu
- Electrical Engineering /= EXTREME rdorich@tufts.edu
- Cornell University __/__, dorich@ptc.com
- ----------------------------------------------------------------------
-